# 模块化设计-前向
import tensorflow as tf

def get_weight(shape, regularizer): #正则项
    # 给w赋初值，括号内是赋初值方法
    w = tf.Variable(tf.random_normal(shape),dtype = tf.float32) 
    # 表示把每一个正则化的损失，加到总损失中
    tf.add_to_collection('losses',tf.contrib.layers.l2_regularizer(regularizer)(w))
    # 返回w
    return w

def get_bias(shape):
    b = tf.Variable(tf.constant(0.01, shape = shape))
    return b

def forward(x, regularizer):

    w1 = get_weight([2,11], regularizer)
    b1 = get_bias([11])
    y1 = tf.nn.relu(tf.matmul(x, w1)+b1)

    w2 = get_weight([11,1], regularizer)
    b2 = get_bias([1])
    y = tf.matmul(y1, w2)+b2

    return y